package com.example.literaturesystem.controller.category;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.literaturesystem.domain.category.Category;
import com.example.literaturesystem.service.category.ICategorySrevice;
import com.google.gson.Gson;

/**
*@author LMR
*@data 2018年1月30日下午8:46:16
*/
@RestController
@RequestMapping("/category")
public class CategoryController {

	 @Autowired
	    private ICategorySrevice categoryService;
	 
	 @RequestMapping(value = "/query", method = RequestMethod.GET)
	 public String queryCategory(){
		 List<Category> categoryList = categoryService.queryCategory();
		 Gson gson = new Gson();
	     return gson.toJson(categoryList);
	 }
	 
	 @RequestMapping(value = "/query/{param}", method = RequestMethod.GET)
	 public String queryMajor(@PathVariable("param") String param){
		 System.out.println(param);
		 Category category = new Category();
		 category.setCategoryName(param);
		 List<Category> categoryList = categoryService.queryMajor(category);
		 Gson gson = new Gson();
	     return gson.toJson(categoryList);
		 
	 }
}
